#pragma once


#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

#include "BackProp.h"
#include "Grid.h"

struct scrline {
	float rho;
	float theta;
	int avgs;
};

struct diffs {
	float diff;
	int i;
};

bool operator < (const diffs& left, const diffs& right);
bool operator < (const scrline& left, const scrline& right);


class GridImage
{
public:
	CBackProp *bp;

	IplImage* src;
	IplImage* let;
	IplImage* glet;
	IplImage* draw;
	IplImage* grey;
	IplImage* hsv;
	IplImage* lap;
	IplImage* letters[26];

	CvFont font;
	CvFont fontdisp;
	CvSize sz;
	GridImage(void);
	void Display(Grid * grid, char * Folder);
	void Train();
	bool OpenFile(char * file);
	char GetChar(CvRect rect, IplImage * mask);
	bool GetCharacters(char * buff);
	void Smooth(void);
	std::vector<scrline> GetLines(bool horizontal, int separation, int houghthresh);
	bool Intersect(double l1theta, double l1rho, double l2theta, double l2rho, double * intersection);
	bool FindNearestWhite(CvPoint * start);
	~GridImage(void);
};
